package com.sys.gradepaysys.controller.event;

import com.alibaba.fastjson.JSON;
import com.sys.gradepaysys.dao.BaseDao;
import com.sys.gradepaysys.entity.Event;
import com.sys.gradepaysys.entity.ResultData;
import com.sys.gradepaysys.service.EventService;
import com.sys.gradepaysys.service.EventServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

@WebServlet(name = "selectEventList2", value = "/selectEventList2")
public class selectEventList2 extends HttpServlet {
    private EventService eventService = new EventServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            List<Event> events = BaseDao.selectEventList2();
            String s="";
            s = JSON.toJSONString(new ResultData<>(200,null,events));
            response.setContentType("text/json;charset=utf-8");
            response.getWriter().write(s);
        } catch (ParseException e) {
            String s="";
            s = JSON.toJSONString(new ResultData<>(500,e.getMessage(),null));
            response.setContentType("text/json;charset=utf-8");
            response.getWriter().write(s);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  doGet(request, response);
    }
}
